#include "libVIP.hpp"

libVIP::libVIP()
{
    av_register_all();
    avformat_network_init();
    avcodec_register_all();
}

libVIP::~libVIP()
{
    avformat_network_deinit();
}

int libVIP::InitVIP(string _config_filename)
{
    if (IP.InitGlobalBuffer(_config_filename) != 0)
    {
        PrintLog("Failed InitGlobalBuffer. INDEX_001");
        return -1;
    }
    if (IS.InitInputStream(&IP))//难点在于中断后要能很好的自动恢复  
    {
        PrintLog("Failed InitInputStream. INDEX_002");
        return -1;
    }
//    Sleep(5000);
    if (OS.InitOutputStream(&IP))
    {
        PrintLog("Failed InitOutputStream. INDEX_003");
        return -1;
    }

    return 0;
}

int libVIP::InitVIP()
{
    if (IP.ReadConfig(config_filename) != 0)
    {
        PrintLog("Failed InitGlobalBuffer. INDEX_001");
        return -1;
    }
    if (IS.InitInputStream(&IP))//难点在于中断后要能很好的自动恢复  
    {
        PrintLog("Failed InitInputStream. INDEX_002");
        return -1;
    }
    //    Sleep(5000);
    if (OS.InitOutputStream(&IP))
    {
        PrintLog("Failed InitOutputStream. INDEX_003");
        return -1;
    }
    //
    //while (true)
    //{
    //    Sleep(30000);//30s check
    //    if (!IS.GetInputStatus())
    //    {
    //        IS.InitInputStream(&IP);
    //    }

    //}
    return 0;
}
